package com.masterclient.app.modules.cart.holder;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.masterclient.app.R;
import com.masterclient.app.modules.goods.adapter.CommodityRecyclerAdapter;
import com.eoner.commonbean.product.ProductMessage;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.widget.StaggeredGridNoScrollLayoutManager;
import java.util.List;

public class RecommendHolder extends RecyclerView.ViewHolder{

    private CommodityRecyclerAdapter recommendAdapter;

    public RecommendHolder(ViewGroup itemView) {
        super(LayoutInflater.from(itemView.getContext()).inflate(R.layout.view_item_cart_recommon,itemView,false));
        RecyclerView recyclerView = this.itemView.findViewById(R.id.recyclerView);
        StaggeredGridNoScrollLayoutManager layoutManager = new StaggeredGridNoScrollLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(null);
        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                super.getItemOffsets(outRect, view, parent, state);
                outRect.set(ScreenUtils.dp2px(4),ScreenUtils.dp2px(9),ScreenUtils.dp2px(5),0);
            }
        });
        recommendAdapter = new CommodityRecyclerAdapter();
        recommendAdapter.setStrings("购物车","热卖推荐");
        recyclerView.setAdapter(recommendAdapter);
        recommendAdapter.bindToRecyclerView(recyclerView);
    }

    public void onBindViewHolder(List<ProductMessage> itemBean){
        if (itemBean == null){
            return;
        }
        recommendAdapter.setNewData(itemBean);
    }
}
